package com.cweb.framework.util;

import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.SecureUtil;
import cn.hutool.crypto.symmetric.SymmetricAlgorithm;
import cn.hutool.crypto.symmetric.SymmetricCrypto;

/**
 * 密码工具
 */
public class PasswordUtil {

    /**
     * 密码加密
     */
    public static String encryptPasswordAES(String password) {
        if (StrUtil.isBlank(password)) {
            return "";
        }
        // 加密用
        SymmetricCrypto aes = new SymmetricCrypto(SymmetricAlgorithm.AES,
                SecureUtil.generateKey(SymmetricAlgorithm.AES.getValue(), MyConstant.Authority.CONFIG_USER_PASSWORD_ASE.getBytes()).getEncoded());
        return aes.encryptHex(password);
    }
    /**
     * 密码解密
     */
    public static String decryptPasswordAES(String passwordAes) {
        if (StrUtil.isBlank(passwordAes)) {
            return "";
        }
        // 加密用
        SymmetricCrypto aes = new SymmetricCrypto(SymmetricAlgorithm.AES,
                SecureUtil.generateKey(SymmetricAlgorithm.AES.getValue(), MyConstant.Authority.CONFIG_USER_PASSWORD_ASE.getBytes()).getEncoded());
        return aes.decryptStr(passwordAes);
    }
}
